home *** CD-ROM | disk | FTP | other *** search
- Path: msuvx2.memphis.edu!tangh
- From: tangh@cc.memphis.edu
- Newsgroups: comp.lang.c++
- Subject: Problem with file read/write
- Date: 10 Jan 96 08:08:08 -0500
- Organization: The University of Memphis
- Message-ID: <1996Jan10.080808@msuvx2.memphis.edu>
- NNTP-Posting-Host: msuvx2.memphis.edu
-
- Hello, everyone. I am trying to read a data file and read it into another file
- tab delimited. Each field in the data file has fixed position. I am using
- following code to read the string
-
- ifstream in_fp;
- ifstream out_fp;
-
- void main()
- {
- char infile = "test1.txt";
- char outfile = "test2.txt";
- char s1[80], s2[45], s3[7];
-
- ...... // open two files
-
-
- in_fp.read(s1, 80);
- s1[7] = '\09'; // insert a tab at position 7
- s1[14] = '\09'; // insert a tab at position 14
- s2[9] = '\09'; // insert a tab at pos 9 for the second line of record
- strcat(s1, s2); // merge two lines of record into one line
-
- out_fp.write(s1, 131); // write to the output file
-
- ... // close two files
- }
-
- The problem is if there are record missing at certain position, it will read
- next field and move the field position. Also, this piece of code also write
- some other garbge into the file. Could someone help me see what's wrong with
- it? Thanks, Hua.
-
-
-
-
-